<template>
    <div>
        <el-dialog
            :model-value="show"
            :show-close="showClose"
            :draggable="true"
            :close-on-click-modal="false"
            :title="title"
            :width="width"
            class="cust-dialog"
            :top="top"
            @close="close"
        >
            <div class="dialog-body">
                <slot></slot>
            </div>
            <template
                #footer
                v-if="buttons && buttons.length > 0"
            >
                <div class="dialog-footer">
                    <el-button
                        type="primary"
                        @click="close"
                        v-if="showCancel"
                    >取消</el-button>
                    <el-button
                        :type="btn.type || 'default'"
                        @click="btn.click"
                        v-for="btn in buttons"
                        :key="btn.id"
                    >{{
                        btn.text
                    }}</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup>
const props = defineProps({
    show: {
        type: Boolean,
        default: true
    },
    title: {
        type: String,
        default: "biaoti1"
    },
    showClose: {
        type: Boolean,
        default: true
    },
    top: {
        type: String,
        default: "50px"
    },
    buttons: {
        type: Array,
    },
    showCancel: {
        type: Boolean,
        default: true
    },
    width: {
        type: String,
        default: "25%"
    }
});

const emit = defineEmits();
const close = () => {
    emit("close")
}
</script>

<style lang="scss" scoped>
.cust-dialog {
    .el-dialog__body {
        padding: 0;
    }

    .dialog-body {
        border-top: 1px solid #ddd;
        border-bottom: 1px solid #ddd;
        padding: 15px;
        max-height: calc(100vh - 250px);
        overflow-x: auto
    }

    .dialog-footer {
        text-align: right;
        padding: 5px 20px;
    }
}
</style>
